package front.end.subestacao.tests;

import java.io.File;
import java.io.IOException;
import java.util.List;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;

import front.end.subestacao.rede.LugarFusao;
import front.end.subestacao.xml.reader.XmlFile;

/**
 * @author Katy
 *
 */
public class XMLReaderTest extends TestCase {

	private XmlFile xmlFile;

	private List<LugarFusao> lugares;

	

	public XMLReaderTest(String name) {
		super(name);
	}

	public static void main(String[] args) {

		junit.textui.TestRunner.run(suite());

	}

	//
	protected void setUp() {

		try {
			xmlFile = new XmlFile(new File("biblioteca_testes/CH_GG.xml"));
			lugares = xmlFile.getLugares();

		} catch (JDOMException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static Test suite() {
		return new TestSuite(XMLReaderTest.class);

	}

	

	/*
	 * 
	 * O teste abaixo eh feito baseado no seguinte codigo XML extraido do
	 * arquivo CH_GG.xml
	 * 
	 * <name id="id2987">
      <flags mask="false" omit="false" nobound="false" nosizing="true" visible="true"/>
      <lineattr type="solid" thick="0" colour="black"/>
      <fillattr pattern="none" colour="black"/>
      
    </name>
	 */
	public void testGetInformLugar() {
		assertEquals(6, xmlFile.getLugares().size());
		
		Element element = xmlFile.getElementById("name", "id2987");
		List<Element> element_interno = element.getChildren("flags");
		Element campos = element_interno.get(0);
		assertEquals("false", campos.getAttributeValue("mask"));
		assertEquals("false", campos.getAttributeValue("omit"));
		assertEquals("false", campos.getAttributeValue("nobound"));
		assertEquals("true", campos.getAttributeValue("nosizing"));
		assertEquals("true", campos.getAttributeValue("visible"));

		
		
		element_interno = element.getChildren("lineattr");
		campos = element_interno.get(0);
		assertEquals("solid", campos.getAttributeValue("type"));
		assertEquals("0", campos.getAttributeValue("thick"));
		assertEquals("black", campos.getAttributeValue("colour"));

		element_interno = element.getChildren("fillattr");
		campos = element_interno.get(0);
		assertEquals("none", campos.getAttributeValue("pattern"));
		assertEquals("black", campos.getAttributeValue("colour"));
		
	}
	
	

}